package ecg.dao;

import java.io.IOException;
import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;

public class DaoService {
	private static DaoManager daoManager;
	
	public static synchronized DaoManager getInstance() {
		String daoXmlResource = "dao.xml";
		
		Reader reader = null;
		
		if(null==daoManager){
			
			try{
				reader=Resources.getResourceAsReader(daoXmlResource);
				
				daoManager=DaoManagerBuilder.buildDaoManager(reader);
				
			}catch(IOException e){
				throw new RuntimeException("Unable to create DAO Manager.", e);
			}
		}
		
		return daoManager;
	}
	
	public static Object getDao(Class interfaceClass, String con){
		return getInstance().getDao(interfaceClass, con);    
	}
}
